using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Security;
using CSI.Directory.Core.Model;
using CSI.Directory.Core.Services;
using StructureMap;

namespace CSI.Directory.Web.Controllers
{
    public class LoginController : BaseController
    {
        
        public ActionResult Index(string returnUrl)
        {
            return View("Login");
        }

        public ActionResult Management()
        {
            return View("~/Views/Management/Login.aspx");
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult ManagementLogin(string email, string password, string keep)
        {

            var keepme = (!string.IsNullOrEmpty(keep) && keep.Equals("on")) ? true : false;
            return Json(UserService.LoginUser(email, password, keepme));
        }
        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult Do(string email, string password, string keep)
        {

            var keepme = (!string.IsNullOrEmpty(keep) && keep.Equals("on")) ? true : false;
            return Json(UserService.LoginUser(email, password, keepme));
        }

        public ActionResult Out()
        {
            UserService.LogoutUser();
            return RedirectToRoute(new { Controller = "Home", Action = "Index" });
        }

        public JsonResult Reset(string email)
        {
            return Json(UserService.ResetPassword(email));
        }
        //[AcceptVerbs(HttpVerbs.Post)]
        //public JsonResult SendReminder(string username, string email)
        //{
        //    var t = new TransactionResult() { Successful = false };

        //    if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(email))
        //        return Json(t);

        //    return Json(UserService.SendPasswordReminder(username, email));
        //}

        public ActionResult Manage()
        {
            return View("Manage");
        }

        
        public ActionResult ManagementLogout()
        {
            UserService.LogoutUser();
            return View("Manage");
        }

    }
}